//
//  JiaoyiViewController.m
//  盘盈贷1.2
//
//  Created by iOS on 15/3/13.
//  Copyright (c) 2015年 iOS. All rights reserved.
//

#import "JiaoyiViewController.h"
#import "JiaoyiTableViewCell.h"
#import "AFHTTPRequestOperationManager.h"
#import "Jiaoyi.h"
@interface JiaoyiViewController ()<UITableViewDataSource, UITableViewDelegate>
@property (nonatomic, retain)UITableView *tableView;
@property (nonatomic, retain)NSMutableArray *array;

@end

@implementation JiaoyiViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        
        self.title = @"交易记录";
        self.array = [NSMutableArray array];
        
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    // Do any additional setup after loading the view.
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height) style:UITableViewStylePlain];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.rowHeight = 80;
    [self.view addSubview:self.tableView];
    [self.tableView release];
    NSString *str = [NSString stringWithFormat:@"http://www.cloudpeng.com:8102/account/getfundflow?strusername=%@", self.strusername];
//    NSString *str =@"http://www.cloudpeng.com:8102/account/getfundflow?strusername=chenying";
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    //manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"text/html"];
    [manager GET:str parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
        for (NSDictionary *dic in responseObject) {
            Jiaoyi *model = [[Jiaoyi alloc] initWithDictionary:dic];
            [self.array addObject:model];
            
        }
        
        [self.tableView reloadData];
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        NSLog(@"___________%@",error);
    }];
    
    [self.tableView reloadData];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [self.array count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    JiaoyiTableViewCell *cell = [[JiaoyiTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"reuse"];
    if (cell == nil) {
        cell = [tableView dequeueReusableCellWithIdentifier:@"reuse"];
        
    }
    NSString *time = [[self.array objectAtIndex:indexPath.row] CreateTime];
    NSArray *timearray = [time componentsSeparatedByString:@"T"]; //从字符A中分隔成2个元素的数组
   // NSLog(@"time:%@", [timearray objectAtIndex:1]);
    cell.caozuotime.text = [NSString stringWithFormat:@"%@", [timearray objectAtIndex:0]];
    cell.zhuangtai1.text = [NSString stringWithFormat:@"%@", [[self.array objectAtIndex:indexPath.row] PayStatus]];
    if ([[[self.array objectAtIndex:indexPath.row] Amount] integerValue] > 10000) {
        NSMutableString *t = [NSMutableString stringWithFormat:@"%@.00(元)", [[self.array objectAtIndex:indexPath.row] Amount]];
        [t insertString:@"," atIndex:2];
        cell.yue.text = t;
    }else {
      cell.yue.text = [NSString stringWithFormat:@"%@.00(元)", [[self.array objectAtIndex:indexPath.row] Amount]];
    }
   
    if ([[NSString stringWithFormat:@"%@",[[self.array objectAtIndex:indexPath.row] BillType]]isEqual:@"0"]) {
        cell.mingchen1.text = [NSString stringWithFormat:@"%@", @"所有"];
        
    }else if ([[NSString stringWithFormat:@"%@",[[self.array objectAtIndex:indexPath.row] BillType]]isEqual:@"1"]){
        cell.mingchen1.text = @"充值";
    }else if ([[NSString stringWithFormat:@"%@",[[self.array objectAtIndex:indexPath.row] BillType]]isEqual:@"2"]){
         cell.mingchen1.text = @"提现";
    }else if ([[NSString stringWithFormat:@"%@",[[self.array objectAtIndex:indexPath.row] BillType]]isEqual:@"3"]) {
        cell.mingchen1.text =  [NSString stringWithFormat:@"%@", @"投标"];
    }else if ([[NSString stringWithFormat:@"%@",[[self.array objectAtIndex:indexPath.row] BillType]]isEqual:@"4"]) {
        cell.mingchen1.text = @"投资";
    }else if ([[NSString stringWithFormat:@"%@",[[self.array objectAtIndex:indexPath.row] BillType]]isEqual:@"5"]) {
        cell.mingchen1.text = @"还款";
    }else if ([[NSString stringWithFormat:@"%@",[[self.array objectAtIndex:indexPath.row] BillType]]isEqual:@"6"]) {
        cell.mingchen1.text = @"收款";
    }else if ([[NSString stringWithFormat:@"%@",[[self.array objectAtIndex:indexPath.row] BillType]]isEqual:@"7"]) {
        cell.mingchen1.text = @"借款成功";
    }else if ([[NSString stringWithFormat:@"%@",[[self.array objectAtIndex:indexPath.row] BillType]]isEqual:@"8"]) {
        cell.mingchen1.text = @"充值手续费";
    }else if ([[NSString stringWithFormat:@"%@",[[self.array objectAtIndex:indexPath.row] BillType]]isEqual:@"9"]) {
        cell.mingchen1.text = @"提现手续费";
    }else if ([[NSString stringWithFormat:@"%@",[[self.array objectAtIndex:indexPath.row] BillType]]isEqual:@"10"]) {
        cell.mingchen1.text = @"借款服务费";
    }else if ([[NSString stringWithFormat:@"%@",[[self.array objectAtIndex:indexPath.row] BillType]]isEqual:@"11"]) {
        cell.mingchen1.text = @"解冻";
    }else if ([[NSString stringWithFormat:@"%@",[[self.array objectAtIndex:indexPath.row] BillType]]isEqual:@"12"]) {
        cell.mingchen1.text = @"债权转让成功";
    }else if ([[NSString stringWithFormat:@"%@",[[self.array objectAtIndex:indexPath.row] BillType]]isEqual:@"13"]) {
        cell.mingchen1.text = @"转让手续费";
    }else if ([[NSString stringWithFormat:@"%@",[[self.array objectAtIndex:indexPath.row] BillType]]isEqual:@"14"]) {
        cell.mingchen1.text = @"转账";
    }else if ([[NSString stringWithFormat:@"%@",[[self.array objectAtIndex:indexPath.row] BillType]]isEqual:@"15"]) {
        cell.mingchen1.text = @"投资启动金";
    }else if ([[NSString stringWithFormat:@"%@",[[self.array objectAtIndex:indexPath.row] BillType]]isEqual:@"16"]) {
        cell.mingchen1.text = @"邀请奖励";
    }else if ([[NSString stringWithFormat:@"%@",[[self.array objectAtIndex:indexPath.row] BillType]]isEqual:@"17"]) {
        cell.mingchen1.text = @"返还众筹利息";
    }else if ([[NSString stringWithFormat:@"%@",[[self.array objectAtIndex:indexPath.row] BillType]]isEqual:@"18"]) {
        cell.mingchen1.text = @"红包提取到余额";
    }else if ([[NSString stringWithFormat:@"%@",[[self.array objectAtIndex:indexPath.row] BillType]]isEqual:@"50"]) {
        cell.mingchen1.text = @"手动冻结";
    }else if ([[NSString stringWithFormat:@"%@",[[self.array objectAtIndex:indexPath.row] BillType]]isEqual:@"51"]) {
        cell.mingchen1.text = @"手动解冻";
    }else if ([[NSString stringWithFormat:@"%@",[[self.array objectAtIndex:indexPath.row] BillType]]isEqual:@"52"]) {
        cell.mingchen1.text = @"手动下拨";
    }else  {
        cell.mingchen1.text = @" 手动归集";
    }
    NSLog(@"%@", [[self.array objectAtIndex:indexPath.row] BillType]);
//    cell.mingchen1.text = [NSString stringWithFormat:@"%@", [[self.array objectAtIndex:indexPath.row] BillType]];
//    NSMutableString *t1 = [NSMutableString stringWithFormat:@"%@.00(元)", [[self.array objectAtIndex:indexPath.row] AfterPayAvailable]];
//    [t1 insertString:@"," atIndex:1];
//    cell.yue.text = t1;
//    cell.shouzhi1.text = [NSString stringWithFormat:@"%@", [[self.array objectAtIndex:indexPath.row] AfterPayAvailable]];
    return cell;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
